package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.domain.SkuStock;
import com.itheima.mapper.SkuStockMapper;
import com.itheima.service.ISkuStockService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * sku的库存 服务实现类
 * </p>
 *
 * @author fukeke
 * @since 2022-11-11
 */
@DubboService
public class SkuStockServiceImpl extends ServiceImpl<SkuStockMapper, SkuStock> implements ISkuStockService {
    @Autowired
    SkuStockMapper skuStockMapper;

    @Override
    public List<SkuStock> selectByProductId(Long productId) {
        LambdaQueryWrapper<SkuStock> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SkuStock::getProductId,productId);
        return skuStockMapper.selectList(queryWrapper);
    }

    @Override
    public void createPmsSkuStock(SkuStock pmsSkuStock) {
        skuStockMapper.insert(pmsSkuStock);
    }

    @Override
    public void update(Integer pid, SkuStock skuStockList) {
        skuStockList.setId(Long.valueOf(pid));
        skuStockMapper.updateById(skuStockList);


    }

    @Override
    public SkuStock getByIdAndSku(Integer pid, String keyword) {
        LambdaQueryWrapper<SkuStock>lqw=new LambdaQueryWrapper<>();
        lqw.eq(pid!=null,SkuStock::getId,pid);
        lqw.like(keyword!=null,SkuStock::getSkuCode,keyword);
        SkuStock skuStock = skuStockMapper.selectOne(lqw);
        return skuStock;

    }
}
